<?php 
require_once (__DIR__ . "/../../models/PaymentMethods.php");
require_once (__DIR__ . "/../../models/Keywords.php");
require_once (__DIR__ . "/../../models/Users.php");

if(isset($_POST['id']))
{
	$row = $_POST;
	$response = PaymentMethods::Validate($row);
	if($response === true)
		$response = PaymentMethods::Update($row);
	if($response === true)
		header("Location: $rootUrl/../W/PaymentMethods/index");
}else{
	$row = PaymentMethods::Get($_REQUEST['id']);
}

?>
				<?php if(isset($response)): ?>
					<dl class="dl-horizontal error">
						<?php foreach ($response as $key => $value): ?>
							<dt><?php echo $key?></dt>
							<dd><?php echo $value?></dd>
						<?php endforeach; ?>						
					</dl>
				<?php endif; ?>
				<form class="form-horizontal" action="" method="post">
					<input type="hidden" name="id" value="<?php echo $row['id']?>" />
					<div class="control-group">
						<label class="control-label" for="paymentType">Payment Type:</label>
						<div class="controls">
<?php $results = Keywords::GetChildren('paymentType'); 
							echo '<select name="paymentType">';
	  while($row2 = $results->fetch_assoc()): 
			if ($row2['id'] == $row['paymentType'])
				echo '<option value="'.$row2['id'].'" selected="selected">'.$row2['name'].'</option>';
			else 
				echo '<option value="'.$row2['id'].'" >'.$row2['name'].'</option>';					
	  endwhile;	
	   						echo '</select>';

						?> 
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="accountNumber">Account Number:</label>
						<div class="controls">
							<input type="tel" name="accountNumber" id="accountNumber" value="<?php echo $row['accountNumber']?>" 
class="<?php echo isset($response['accountNumber']) ? 'error' : '' ?>"
								/>
								<?php if(isset($response['accountNumber'])): ?>
									<span class="error"><?php echo $response['accountNumber']?></span>
								<?php endif; ?>

						</div>
					</div>					
					<div class="control-group">
						<label class="control-label" for="accountType">Account Type:</label>
						<div class="controls">
<?php $results = Keywords::GetChildren('accountType'); 
							echo '<select name="accountType">';
	  while($row2 = $results->fetch_assoc()): 
			if ($row2['id'] == $row['accountType'])
				echo '<option value="'.$row2['id'].'" selected="selected">'.$row2['name'].'</option>';
			else 
				echo '<option value="'.$row2['id'].'" >'.$row2['name'].'</option>';					
	  endwhile;	
	   						echo '</select>';

						?> 
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="expDate">Expiration Date:</label>
						<div class="controls">
							<input type="date" name="expDate" value="<?php echo $row['expDate']?>" 
class="<?php echo isset($response['expDate']) ? 'error' : '' ?>"
								/>
								<?php if(isset($response['expDate'])): ?>
									<span class="error"><?php echo $response['expDate']?></span>
								<?php endif; ?>

						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="userId">User Id:</label>
						<div class="controls">
<?php $results = Users::GetAll(); 
							echo '<select name="userId">';
	  while($row2 = $results->fetch_assoc()): 
			if ($row2['id'] == $row['userId'])
				echo '<option value="'.$row2['id'].'" selected="selected">'.$row2['firstName'].' '.$row2['lastName'].'</option>';
			else 
				echo '<option value="'.$row2['id'].'" >'.$row2['firstName'].' '.$row2['lastName'].'</option>';					
	  endwhile;	
	   						echo '</select>';

						?> 
						</div>
					</div>
					<div class="control-group">
						<div class="controls">
							<input type="submit" value="Save" class="btn btn-primary" />
						</div>
					</div>
			
				</form>